﻿// Decompiled with JetBrains decompiler
// Type: DnProcessSimulateCommands.RenameTool.CApRenameToolManager
// Assembly: DnProcessSimulateCommands, Version=2402.0.0.890, Culture=neutral, PublicKeyToken=null
// MVID: A885D881-AEDF-447E-852A-6F13102E089C
// Assembly location: C:\Program Files\Tecnomatix_2402\eMPower\DotNetCommands\DnProcessSimulateCommands.dll

using EMPAPPLICATIONLib;
using EMPAPPSERVICESLib;
using EMPTRANSACTIONLib;
using EMPTRAVERSALSLib;
using EMPTYPELIBRARYLib;
using EngineeringInternalExtension;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.ComponentModel.Composition.Primitives;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Windows.Media;
using Tecnomatix.Engineering;
using Tecnomatix.Engineering.Ui;
using Tecnomatix.Planning;
using Tecnomatix.Planning.DotNetComponents;
using Tecnomatix.Planning.DotNetFoundation;


namespace DnProcessSimulateCommands.RenameTool;

public class CApRenameToolManager
{
  private CApDataElements elements;
  private RuleBase[] plugins;
  private List<CApRenameElement> _directChildren;
  private List<CApRenameElement> _allChildren;
  private ObservableCollection<CApRenameElement> _parents;
  private List<Type> simulatorForbiddenTypes;
  private bool isLineSimulationStudy;
  private ApplyScope _applyScope;
  private bool isRunningInDesigner;
  private bool isRulesStateSuccess;
  private List<string> filteredObjects;
  private static CApRenameToolManager instance;

  internal CApDataElements GetDataElements => this.elements;

  public ObservableCollection<CApRenameElement> Elements => this.elements.Elements;

  public RuleBase[] Plugins => this.plugins;

  public List<CApRenameElement> DirectChildren
  {
    get => this._directChildren;
    set => this._directChildren = value;
  }

  public List<CApRenameElement> AllChildren
  {
    get => this._allChildren;
    set => this._allChildren = value;
  }

  public ObservableCollection<CApRenameElement> Parents
  {
    get => this._parents;
    set => this._parents = value;
  }

  public ApplyScope ApplyScope
  {
    get => this._applyScope;
    set => this._applyScope = value;
  }

  public bool IsRulesStateSuccess
  {
    get => this.isRulesStateSuccess;
    set => this.isRulesStateSuccess = value;
  }

  public static CApRenameToolManager GetInstance()
  {
    if (CApRenameToolManager.instance == null)
      CApRenameToolManager.instance = new CApRenameToolManager();
    return CApRenameToolManager.instance;
  }

  private CApRenameToolManager()
  {
    this.DirectChildren = new List<CApRenameElement>();
    this.AllChildren = new List<CApRenameElement>();
    this.Parents = new ObservableCollection<CApRenameElement>();
    this.elements = new CApDataElements();
    this.filteredObjects = new List<string>();
    this.simulatorForbiddenTypes = new List<Type>();
    this.InitializeForbiddenTypes();
    this.isLineSimulationStudy = this.IsLineSimulationStudyLoaded();
    this.InitializePlugins();
    this.isRunningInDesigner = false;
    if (!TxApplication.PlatformType.Equals((object) (TxPlatformType) 1) || !((IEmpApplication) new EmpApplicationClass()).RunningApplicationName.Equals("Process Designer"))
      return;
    this.isRunningInDesigner = true;
  }

  private void InitializePlugins()
  {
    CompositionContainer container = new CompositionContainer((ComposablePartCatalog) new AggregateCatalog()
    {
      Catalogs = {
        (ComposablePartCatalog) new AssemblyCatalog(Assembly.GetExecutingAssembly())
      }
    }, Array.Empty<ExportProvider>());
    container.ComposeParts((object) this);
    IEnumerable exports = (IEnumerable) container.GetExports<RuleBase>();
    this.plugins = new RuleBase[exports.Cast<Lazy<RuleBase>>().Count<Lazy<RuleBase>>()];
    foreach (object obj in exports)
    {
      if (this.plugins[((Lazy<RuleBase>) obj).Value.Position - 1] == null)
        this.plugins[((Lazy<RuleBase>) obj).Value.Position - 1] = ((Lazy<RuleBase>) obj).Value;
    }
  }

  public Type[] GetPluginTypes()
  {
    Type[] pluginTypes = new Type[this.plugins.Length];
    int index = 0;
    foreach (RuleBase plugin in this.plugins)
    {
      pluginTypes[index] = plugin.GetType();
      ++index;
    }
    return pluginTypes;
  }

  private void InitializeForbiddenTypes()
  {
    this.simulatorForbiddenTypes.Add(typeof (TxPhysicalRoot));
    this.simulatorForbiddenTypes.Add(typeof (TxMainFolder));
  }

  private bool IsLineSimulationStudyLoaded()
  {
    return TxApplication.ActiveDocument.PlatformGlobalServicesProvider.IsDataLoaded() && TxEngineeringDataInternal.GlobalGetPartsMode() == 2;
  }

  public bool IsRunningInDesigner() => this.isRunningInDesigner;

  public void Clear()
  {
    this.Parents.Clear();
    this.DirectChildren.Clear();
    this.AllChildren.Clear();
    this.elements.Elements.Clear();
  }

  public void ResetManager()
  {
    this.Clear();
    this.filteredObjects.Clear();
  }

  public RuleMessage AddSelectedItems()
  {
    bool flag1 = false;
    bool flag2 = false;
    if (TxApplication.ActiveDocument.Selection.TotalCount < 1)
      return new RuleMessage(true);
    TxObjectList allItems = TxApplication.ActiveDocument.Selection.GetAllItems();
    if (this.IsRunningInDesigner())
    {
      foreach (ITxObject planningRepresentation in (Collection<ITxObject>) ((TxObjectList<ITxObject>) allItems).PlanningRepresentations)
      {
        bool success = false;
        string objectTypeName = this.GetObjectTypeName(planningRepresentation);
        ITxPlanningObject planObj = planningRepresentation as ITxPlanningObject;
        EmpObjectKey empObjectKey = this.GetEmpObjectKey(planObj, out success);
        if (success && !this.Contains(this.Parents.ToList<CApRenameElement>(), empObjectKey))
        {
          CApRenameElement capRenameElement = this.elements.AddRootNode(planObj);
          this.Parents.Add(capRenameElement);
          if (this.filteredObjects.Contains<string>(objectTypeName))
          {
            this.Elements.Remove(capRenameElement);
            flag2 = true;
          }
        }
      }
    }
    else
    {
      foreach (ITxObject itxObject in (Collection<ITxObject>) allItems)
      {
        string objectTypeName = this.GetObjectTypeName(itxObject);
        if (this.IsValidObject(itxObject))
        {
          if (!this.Contains(this.Parents.ToList<CApRenameElement>(), itxObject))
          {
            CApRenameElement capRenameElement = this.elements.AddRootNode(itxObject);
            this.Parents.Add(capRenameElement);
            if (this.filteredObjects.Contains<string>(objectTypeName))
            {
              this.Elements.Remove(capRenameElement);
              flag2 = true;
            }
          }
        }
        else
          flag1 = true;
      }
      if (flag1)
        return new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_SKIPPED_OBJECTS"));
    }
    return flag2 ? new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_FILTERED_OBJECTS")) : new RuleMessage(true);
  }

  private EmpObjectKey GetEmpObjectKey(ITxPlanningObject planObj, out bool success)
  {
    EmpObjectKey empObjectKey = new EmpObjectKey();
    empObjectKey.objectId = -1;
    if (planObj != null)
    {
      ITxEmsServicesProvider servicesProvider = (ITxEmsServicesProvider) planObj.PlatformServicesProvider;
      empObjectKey.objectId = servicesProvider.InternalId;
      if (empObjectKey.objectId == 0)
      {
        success = false;
        return empObjectKey;
      }
      success = true;
      return empObjectKey;
    }
    success = false;
    return empObjectKey;
  }

  public RuleMessage AddChildren(List<CApRenameElement> newElements, bool addDirectChildrenOnly)
  {
    RuleMessage ruleMessage = (RuleMessage) null;
    List<CApRenameElement> collection = new List<CApRenameElement>();
    if (this.IsRunningInDesigner())
    {
      EmpObjectKey[] rootNodes = new EmpObjectKey[newElements.Count];
      for (int index = 0; index < rootNodes.Length; ++index)
        rootNodes[index] = newElements[index].Key;
      foreach (EmpObjectKey child in this.GetChildren(rootNodes, addDirectChildrenOnly))
        collection.Add(this.elements.AddRootNode(child));
    }
    else
    {
      ITxObject[] rootNodes = new ITxObject[newElements.Count];
      for (int index = 0; index < rootNodes.Length; ++index)
        rootNodes[index] = newElements[index].Obj;
      List<ITxObject> children = this.GetChildren(rootNodes, addDirectChildrenOnly);
      bool flag = true;
      foreach (ITxObject itxObject in children)
      {
        if (this.IsValidObject(itxObject))
          collection.Add(this.elements.AddRootNode(itxObject));
        else
          flag = false;
      }
      if (!flag)
        ruleMessage = new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_SKIPPED_OBJECTS"));
    }
    if (addDirectChildrenOnly)
    {
      this.DirectChildren.Clear();
      this.DirectChildren.AddRange((IEnumerable<CApRenameElement>) collection);
    }
    else
    {
      this.AllChildren.Clear();
      this.AllChildren.AddRange((IEnumerable<CApRenameElement>) collection);
    }
    if (ruleMessage == null)
      ruleMessage = new RuleMessage(true);
    return ruleMessage;
  }

  private List<ITxObject> GetChildren(ITxObject[] rootNodes, bool getDirectChildrenOnly)
  {
    TxNoTypeFilter txNoTypeFilter = new TxNoTypeFilter();
    List<ITxObject> children = new List<ITxObject>();
    foreach (ITxObject rootNode in rootNodes)
    {
      if (rootNode is ITxObjectCollection)
      {
        if (getDirectChildrenOnly)
        {
          children.AddRange((IEnumerable<ITxObject>) ((IEnumerable<ITxObject>) (rootNode as ITxObjectCollection).GetDirectDescendants((ITxTypeFilter) txNoTypeFilter)).ToList<ITxObject>());
        }
        else
        {
          children.AddRange((IEnumerable<ITxObject>) ((IEnumerable<ITxObject>) (rootNode as ITxObjectCollection).GetAllDescendants((ITxTypeFilter) txNoTypeFilter)).ToList<ITxObject>());
          children.RemoveAll((Predicate<ITxObject>) (o => o.IsTransient));
        }
      }
    }
    return children;
  }

  private List<EmpObjectKey> GetChildren(EmpObjectKey[] rootNodes, bool getDirectChildrenOnly)
  {
    EmpContext empContext;
    empContext.sessionId = TxApplication.ActiveDocument.eMSSessionId;
    List<EmpObjectKey> children = new List<EmpObjectKey>();
    List<int> intList = new List<int>();
    EmpReadTransaction empReadTransaction = (EmpReadTransaction) null;
    try
    {
      empReadTransaction = (EmpReadTransaction) new EmpReadTransactionClass();
      bool flag1 = true;
      bool flag2 = true;
      bool flag3 = false;
      EmpTraversePath[] empTraversePathArray = new EmpTraversePath[1];
      empTraversePathArray[0].From_ClassName = "PmNode";
      empTraversePathArray[0].To_FieldName = "children";
      string[] strArray = new string[0];
      List<string> source1 = new List<string>();
      List<EmpClassFields> source2 = new List<EmpClassFields>();
      source2.Add(this.CreateClassField("PmNode", new string[1]
      {
        "Ex_classDef"
      }));
      source1.Add("PmNode");
      string[] array1 = source1.ToArray<string>();
      EmpClassFields[] array2 = source2.ToArray<EmpClassFields>();
      EmpTypeCollectorEx instance = (EmpTypeCollectorEx) ((IEmpTransactionVB) empReadTransaction).CreateInstance(ref empContext, "EmpTraversals.EmpTypeCollectorEx");
      int num = getDirectChildrenOnly ? 1 : -1;
      ((IEmpTypeCollectorEx) instance).DefineTraversal(ref empContext, ref rootNodes, num, ref empTraversePathArray, ref array1, ref strArray, flag1, (EmpEnumTraverseType) 0, flag2, flag3, ref array2);
      bool flag4 = false;
      do
      {
        foreach (EmpFieldInfo empFieldInfo in ((IEmpTypeCollectorEx) instance).GetNextFieldsChunk(ref flag4))
        {
          EmpObjectKey nodeKey = empFieldInfo.NodeKey;
          if (empFieldInfo.NodeKey.objectId == 0 || this.Contains(this.Parents.ToList<CApRenameElement>(), empFieldInfo.NodeKey))
          {
            if (!intList.Contains(empFieldInfo.NodeKey.objectId))
            {
              intList.Add(empFieldInfo.NodeKey.objectId);
              continue;
            }
            children.Add(empFieldInfo.NodeKey);
          }
          if (empFieldInfo.Value != null && !intList.Contains(empFieldInfo.NodeKey.objectId))
          {
            children.Add(empFieldInfo.NodeKey);
            intList.Add(empFieldInfo.NodeKey.objectId);
          }
        }
      }
      while (!flag4);
      ((IEmpTransactionVB) empReadTransaction).Commit(ref empContext);
      empReadTransaction = (EmpReadTransaction) null;
    }
    finally
    {
      ((IEmpTransactionVB) empReadTransaction)?.Abort(ref empContext);
    }
    return children;
  }

  private bool Contains(List<CApRenameElement> list, EmpObjectKey key)
  {
    bool flag = false;
    foreach (CApRenameElement capRenameElement in list)
    {
      if (capRenameElement.Key.objectId == key.objectId)
      {
        flag = true;
        break;
      }
    }
    return flag;
  }

  private EmpClassFields CreateClassField(string className, string[] fieldNames)
  {
    return new EmpClassFields()
    {
      className = className,
      FieldNames = fieldNames
    };
  }

  private bool Contains(List<CApRenameElement> list, ITxObject obj)
  {
    bool flag = false;
    foreach (CApRenameElement capRenameElement in list)
    {
      if (capRenameElement.Obj.Id == obj.Id)
      {
        flag = true;
        break;
      }
    }
    return flag;
  }

  public void RefreshObjectNames(ref List<EmpObjectKey> keys, List<string> captions)
  {
    for (int index = 0; index < keys.Count; ++index)
    {
      foreach (CApRenameElement element in (Collection<CApRenameElement>) this.elements.Elements)
      {
        if (element.Key.objectId == keys[index].objectId && !captions[index].Equals(""))
          element.Name = captions[index];
      }
    }
  }

  public void RefreshObjectNames(ref List<ITxObject> keys, List<string> captions)
  {
    for (int index = 0; index < keys.Count; ++index)
    {
      foreach (CApRenameElement element in (Collection<CApRenameElement>) this.elements.Elements)
      {
        if (element.Obj.Id == keys[index].Id && !captions[index].Equals(""))
          element.Name = captions[index];
      }
    }
  }

  public RuleMessage SetObjectsCaption(ref List<ITxObject> obj, List<string> captions)
  {
    SetObjectNameFunc setObjectNameFunc = !TxEmsUtilities.IsInCaptionDisplayNameMode() ? new SetObjectNameFunc(this.SetObjectName) : new SetObjectNameFunc(this.SetObjectRawName);
    bool flag = false;
    TxApplication.ActiveUndoManager.StartTransaction();
    for (int index = 0; index < obj.Count; ++index)
    {
      try
      {
        if (!captions[index].Equals(""))
          setObjectNameFunc(obj[index], captions[index]);
      }
      catch (Exception ex)
      {
        flag = true;
      }
    }
    TxApplication.ActiveUndoManager.EndTransaction();
    return flag ? new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_ERROR_DURING_RENAMING")) : new RuleMessage(true);
  }

  public RuleMessage SetObjectsCaption(ref List<EmpObjectKey> keys, List<string> captions)
  {
    EmpNodesServices empNodesServices = (EmpNodesServices) new EmpNodesServicesClass();
    bool flag = false;
    List<EmpNodeFieldsValues> source = new List<EmpNodeFieldsValues>();
    for (int index = 0; index < keys.Count; ++index)
    {
      if (!captions[index].Equals(""))
      {
        List<EmpNodeFieldsValues> nodeFieldsValuesList = source;
        EmpNodeFieldsValues nodeFieldsValues1 = new EmpNodeFieldsValues();
        nodeFieldsValues1.Node = keys[index];
        // ISSUE: explicit reference operation
        (^ref nodeFieldsValues1).FieldsValues = new EmpFieldValue[1]
        {
          new EmpFieldValue()
          {
            FieldValue = (object) captions[index],
            fieldName = "name"
          }
        };
        EmpNodeFieldsValues nodeFieldsValues2 = nodeFieldsValues1;
        nodeFieldsValuesList.Add(nodeFieldsValues2);
      }
    }
    EmpNodeFieldsValues[] array = source.ToArray<EmpNodeFieldsValues>();
    if (array.Length != 0)
    {
      try
      {
        ((IEmpNodesServices) empNodesServices).SetFields(ref this.elements.context, ref array);
      }
      catch (Exception ex)
      {
        flag = true;
      }
    }
    return flag ? new RuleMessage(false, XamlResourceManager.GetString("RENAME_TOOL_ERROR_DURING_RENAMING")) : new RuleMessage(true);
  }

  private bool IsValidObject(ITxObject obj)
  {
    bool flag = true;
    if (obj is ITxPlanningObject)
    {
      TxPlanningObject txPlanningObject = obj as TxPlanningObject;
      ITxObject engineeringRepresentation = txPlanningObject.EngineeringRepresentation;
      if (!txPlanningObject.IsObjectLoaded())
        return false;
    }
    if (!TxObjectEx.CanBeRenamedInCaptionMode(obj))
      return false;
    foreach (Type simulatorForbiddenType in this.simulatorForbiddenTypes)
    {
      if (simulatorForbiddenType.Equals(obj.GetType()))
        return false;
    }
    if (obj.GetType().Equals(typeof (TxPartAppearance)))
      flag = !this.isLineSimulationStudy && this.ParentIsPhysicalRoot(obj);
    return flag;
  }

  private bool ParentIsPhysicalRoot(ITxObject obj)
  {
    bool flag = false;
    if (obj != null)
    {
      try
      {
        ITxObjectCollection collection = obj.Collection;
        if (collection != null)
        {
          if (collection is TxPhysicalRoot)
            flag = true;
        }
      }
      catch (Exception ex)
      {
      }
    }
    return flag;
  }

  public List<CApRenameElement> GetTypesList()
  {
    List<CApRenameElement> typesList = new List<CApRenameElement>();
    List<string> stringList = new List<string>();
    List<CApRenameElement> capRenameElementList = (List<CApRenameElement>) null;
    switch (this.ApplyScope)
    {
      case ApplyScope.Parents:
        capRenameElementList = this.Parents.ToList<CApRenameElement>();
        break;
      case ApplyScope.DirectChildren:
        capRenameElementList = this.DirectChildren;
        break;
      case ApplyScope.AllChildren:
        capRenameElementList = this.AllChildren;
        break;
    }
    foreach (CApRenameElement capRenameElement1 in capRenameElementList)
    {
      CApRenameElement capRenameElement2 = new CApRenameElement();
      capRenameElement2.Icon = this.GetObjectIcon(capRenameElement1.Obj);
      if (capRenameElement2.Icon == null)
        capRenameElement2.Icon = capRenameElement1.Icon;
      if (this.IsRunningInDesigner())
      {
        capRenameElement2.ObjectType = ((DnfTypeDef) capRenameElement1.ClassDef).GetName();
        capRenameElement2.Name = ((DnfTypeDef) capRenameElement1.ClassDef).GetNiceName();
      }
      else
      {
        capRenameElement2.Name = this.GetObjectTypeNiceName(capRenameElement1.Obj);
        capRenameElement2.ObjectType = this.GetObjectTypeName(capRenameElement1.Obj);
      }
      capRenameElement2.Obj = capRenameElement1.Obj;
      capRenameElement2.IsChecked = true;
      if (!stringList.Contains(capRenameElement2.Name))
      {
        stringList.Add(capRenameElement2.Name);
        typesList.Add(capRenameElement2);
      }
    }
    return typesList;
  }

  public string GetObjectTypeName(CApRenameElement obj)
  {
    return this.IsRunningInDesigner() ? ((DnfTypeDef) obj.ClassDef).GetName() : this.GetObjectTypeName(obj.Obj);
  }

  public string GetObjectTypeName(ITxObject obj)
  {
    ITxPlanningObject planningRep = this.GetPlanningRep(obj);
    if (planningRep == null)
      return obj.GetType().Name;
    TxPlanningTypeMetaData typeMetaData = CApRenameToolManager.GetTypeMetaData(planningRep.PlanningType);
    return typeMetaData == null ? obj.GetType().Name : typeMetaData.TypeName;
  }

  public string GetObjectTypeNiceName(ITxObject obj)
  {
    ITxPlanningObject planningRep = this.GetPlanningRep(obj);
    if (planningRep == null)
      return obj.GetType().Name.Remove(0, 2);
    TxPlanningTypeMetaData typeMetaData = CApRenameToolManager.GetTypeMetaData(planningRep.PlanningType);
    if (typeMetaData != null)
      return typeMetaData.DisplayName;
    string objectTypeNiceName = planningRep.PlanningType;
    if (objectTypeNiceName.StartsWith("Pm") || objectTypeNiceName.StartsWith("Tx"))
      objectTypeNiceName = objectTypeNiceName.Remove(0, 2);
    return objectTypeNiceName;
  }

  public ImageSource GetObjectIcon(ITxObject obj)
  {
    ITxPlanningObject planningRep = this.GetPlanningRep(obj);
    return planningRep == null ? (ImageSource) null : this.GetIconFromType(planningRep.PlanningType);
  }

  internal ImageSource GetIconFromType(string planningType)
  {
    Image imageByPlanningType = TxImageProvider.GetImageByPlanningType(planningType);
    return imageByPlanningType == null ? (ImageSource) null : TxImageUtilitiesEx.ImageToImageSource(imageByPlanningType);
  }

  public void FilterScopeObjects(List<string> objects)
  {
    this.Elements.Clear();
    this.filteredObjects = objects;
    List<CApRenameElement> capRenameElementList = (List<CApRenameElement>) null;
    switch (this.ApplyScope)
    {
      case ApplyScope.Parents:
        capRenameElementList = this.Parents.ToList<CApRenameElement>();
        break;
      case ApplyScope.DirectChildren:
        capRenameElementList = this.DirectChildren;
        break;
      case ApplyScope.AllChildren:
        capRenameElementList = this.AllChildren;
        break;
    }
    foreach (CApRenameElement capRenameElement in capRenameElementList)
    {
      if (!objects.Contains<string>(this.GetObjectTypeName(capRenameElement)))
        this.Elements.Add(capRenameElement);
    }
  }

  private ITxPlanningObject GetPlanningRep(ITxObject obj)
  {
    switch (obj)
    {
      case ITxProcessModelObject processModelObject:
        pattern_0 = processModelObject.PlanningRepresentation;
        break;
    }
    return pattern_0;
  }

  internal static TxPlanningTypeMetaData GetTypeMetaData(string type)
  {
    TxPlanningTypeMetaData typeMetaData = (TxPlanningTypeMetaData) null;
    ITxPlatformGlobalServicesProvider servicesProvider = TxApplication.ActiveDocument.PlatformGlobalServicesProvider;
    if (servicesProvider != null)
      typeMetaData = servicesProvider.GetTypeMetaData(type);
    return typeMetaData;
  }

  internal List<Dictionary<string, string>> GetAttributesValuesAsString(
    List<string> attributes,
    out RuleState ruleStateRes)
  {
    ruleStateRes = RuleState.Success;
    if (!this.IsRunningInDesigner())
      return (List<Dictionary<string, string>>) null;
    if (attributes == null || attributes.Count < 1)
      return (List<Dictionary<string, string>>) null;
    Tuple<EmpObjectKey[], string[]> objectsAndAttributes = this.elements.GetCheckedObjectsAndAttributes(attributes);
    EmpObjectKey[] empObjectKeyArray = objectsAndAttributes.Item1;
    string[] requestedAttributes = objectsAndAttributes.Item2;
    if (empObjectKeyArray.Length != 0 && requestedAttributes.Length != 0)
    {
      EmpContext empContext = new EmpContext()
      {
        sessionId = TxApplication.ActiveDocument.eMSSessionId
      };
      this.elements.UpdateAttributes(new EmpNodesServicesClass().GetFieldsEx(ref empContext, ref empObjectKeyArray, ref requestedAttributes), requestedAttributes);
    }
    IEnumerable<string> wrongAttributes;
    List<Dictionary<string, string>> attributesValues = this.elements.GetAttributesValues(attributes, out wrongAttributes);
    if (wrongAttributes.Count<string>() > 0)
      ruleStateRes = RuleState.Error;
    return attributesValues;
  }

  internal static string ReplaceNewLineWithSpace(string val) => val.Replace("\r\n", " ");

  public static bool FilterSimpleTypesOnly(DncfFieldDef field)
  {
    if (field.FieldDef.IsReferenceField)
      return false;
    return field.FieldDef.GetFieldType() == 1 || field.FieldDef.GetFieldType() == 2;
  }

  public static string[] GetSerializedAttributesNames(DncfFieldDef[] fields, char star, char end)
  {
    string[] serializedAttributesNames = new string[fields.Length];
    for (int index = 0; index < fields.Length; ++index)
      serializedAttributesNames[index] = star.ToString() + fields[index].FieldDef.GetName() + end.ToString();
    return serializedAttributesNames;
  }

  internal void SetObjectName(ITxObject obj, string name) => obj.Name = name;

  internal void SetObjectRawName(ITxObject obj, string name)
  {
    TxObjectEx.SetDisplayNameByComputing(obj, name);
  }
}
